<?php
class ControllerCommonLgiHeader extends Controller {
  public function index() {
    $data['title'] = $this->document->getTitle();

    if ($this->request->server['HTTPS']) {
      $data['base'] = HTTPS_SERVER;
    } else {
      $data['base'] = HTTP_SERVER;
    }

    $data['description'] = $this->document->getDescription();
    $data['keywords'] = $this->document->getKeywords();
    $data['links'] = $this->document->getLinks();
    $data['styles'] = $this->document->getStyles();
    $data['scripts'] = $this->document->getScripts();
    $data['lang'] = $this->language->get('code');
    $data['direction'] = $this->language->get('direction');

    $this->load->language('common/lgi_header');

    $data['heading_title'] = $this->language->get('heading_title');

    $data['text_order'] = $this->language->get('text_order');
    $data['text_order_status'] = $this->language->get('text_order_status');
    $data['text_complete_status'] = $this->language->get('text_complete_status');
    $data['text_return'] = $this->language->get('text_return');
    $data['text_customer'] = $this->language->get('text_customer');
    $data['text_online'] = $this->language->get('text_online');
    $data['text_approval'] = $this->language->get('text_approval');
    $data['text_product'] = $this->language->get('text_product');
    $data['text_stock'] = $this->language->get('text_stock');
    $data['text_review'] = $this->language->get('text_review');
    $data['text_affiliate'] = $this->language->get('text_affiliate');
    $data['text_store'] = $this->language->get('text_store');
    $data['text_front'] = $this->language->get('text_front');
    $data['text_help'] = $this->language->get('text_help');
    $data['text_homepage'] = $this->language->get('text_homepage');
    $data['text_documentation'] = $this->language->get('text_documentation');
    $data['text_support'] = $this->language->get('text_support');
    $data['text_logged'] = sprintf($this->language->get('text_logged'), $this->user->getUserName());
    $data['text_logout'] = $this->language->get('text_logout');

    if (!isset($this->request->get['token']) || !isset($this->session->data['token']) && ($this->request->get['token'] != $this->session->data['token'])) {
      $data['logged'] = '';
      $data['home'] = $this->url->link('sale/lgi_order', '', 'SSL');
    } else {
      $data['logged'] = true;
      $data['home'] = $this->url->link('sale/lgi_order', 'token=' . $this->session->data['token'], 'SSL');

      $data['logout'] = $this->url->link('common/logout', 'token=' . $this->session->data['token'], 'SSL');

      // Orders
      $this->load->model('sale/lgi_order');

      // Processing Orders
      $data['order_status_total'] = $this->model_sale_lgi_order->getTotalOrders(array('filter_order_status' => implode(',', $this->config->get('config_processing_status'))));
      $data['order_status'] = $this->url->link('sale/lgi_order', 'token=' . $this->session->data['token'] . '&filter_order_status=' . implode(',', $this->config->get('config_processing_status')), 'SSL');

      // Complete Orders
      $data['complete_status_total'] = $this->model_sale_lgi_order->getTotalOrders(array('filter_order_status' => implode(',', $this->config->get('config_complete_status'))));
      $data['complete_status'] = $this->url->link('sale/lgi_order', 'token=' . $this->session->data['token'] . '&filter_order_status=' . implode(',', $this->config->get('config_complete_status')), 'SSL');

      // Products
      $this->load->model('catalog/lgi_product');

      $product_total = $this->model_catalog_lgi_product->getTotalProducts(array('filter_quantity' => 0));

      $data['product_total'] = $product_total;

      $data['product'] = $this->url->link('catalog/lgi_product', 'token=' . $this->session->data['token'] . '&filter_quantity=0', 'SSL');
      
      // Products Pending Approval
      $this->load->model('catalog/lgi_product');

      $product_pending_approval_total = $this->model_catalog_lgi_product->getTotalProducts(array('filter_status' => 5));

      $data['product_pending_approval_total'] = $product_pending_approval_total;

      $data['product_pending_approval'] = $this->url->link('catalog/lgi_product', 'token=' . $this->session->data['token'] . '&filter_status=5', 'SSL');

      $data['alerts'] = $product_total + $product_pending_approval_total;

      // Online Stores
      $data['stores'] = array();

      $data['stores'][] = array(
        'name' => $this->config->get('config_name'),
        'href' => HTTP_CATALOG
      );

      $this->load->model('setting/store');

      $results = $this->model_setting_store->getStores();

      foreach ($results as $result) {
        $data['stores'][] = array(
          'name' => $result['name'],
          'href' => $result['url']
        );
      }
    }

    return $this->load->view('common/lgi_header.tpl', $data);
  }
}